
use ggez::{glam::Vec2, Context, graphics, mint::Point2};

use crate::particle;

pub struct PArrow {
    particle: particle::Particle,
}

impl PArrow {
    pub fn new(location: Vec2) -> PArrow {
        let particle = particle::Particle::new(location);
        PArrow { particle }
    }
}

impl particle::ParticleLike for PArrow {
    fn is_dead(&self) -> bool {
        self.particle.is_dead()
    }

    fn get_mass(&self) -> f32 {
        self.particle.get_mass()
    }

    fn apply_force(&mut self, force: Vec2) -> () {
        self.particle.apply_force(2.0*force)
    }

    fn update(&mut self) -> () {
        self.particle.size -= 0.2;
        self.particle.update()
    }

    fn display(&self, ctx: &mut Context, canvas : &mut graphics::Canvas) -> () {

        let polygon = graphics::Mesh::new_polygon(
            ctx, 
            graphics::DrawMode::fill(), 
            &[Point2{x: 0.0, y: -3.0*self.particle.size}, Point2{x: 2.0*self.particle.size, y: 3.0*self.particle.size}, Point2{x: 0.0, y: 0.0}, Point2{x: -2.0*self.particle.size, y: 3.0*self.particle.size}], 
            graphics::Color::new(0.7, 0.7, 0.7, self.particle.lifespan)).unwrap();
        canvas.draw(&polygon, graphics::DrawParam::default().dest(self.particle.location).rotation(self.particle.angle)); 
    
        let polygon = graphics::Mesh::new_polygon(
            ctx, 
            graphics::DrawMode::stroke(2.0), 
            &[Point2{x: 0.0, y: -3.0*self.particle.size}, Point2{x: 2.0*self.particle.size, y: 3.0*self.particle.size}, Point2{x: 0.0, y: 0.0}, Point2{x: -2.0*self.particle.size, y: 3.0*self.particle.size}], 
            graphics::Color::new(0.0, 0.0, 0.0, self.particle.lifespan)).unwrap();
        canvas.draw(&polygon, graphics::DrawParam::default().dest(self.particle.location).rotation(self.particle.angle)); 
    }
}